// 点击同意框，立即注册变色
$("#agreebox").click(function(e){
    let bool = $("#agreebox").prop('checked');
    if(bool){
        $(this).parent().siblings('.zhu').find('input').css('background-color', '#f60');
    }else{
        $(this).parent().siblings('.zhu').find('input').css('background-color', '#ccc');
    }
})



// 表单验证

$().ready(function () {
    // 在键盘按下并释放及提交后验证提交表单
    $("#myForm").validate({
        rules: {
            username: {
                required: true,
                isUserName: true,
            },
            password: {
                required: true,
                isPassWord: true,
            },
            confirm_password: {
                required: true,
                isPassWord: true,
                equalTo: "#password"
            },
            phone_number: {
                required: true,
                isPhone_number:true,
            },
            code: {
                required: true,
            },
            phone_code: {
                required: true,
            },
            tongyi: {
                required: true,
            },

            agree: "required"
        },

        messages: {
            username: {
                required: "请输入用户名",
                isUserName: "用户名必需由6-12个字符组成"
            },
            password: {
                required: "请输入密码",
                isPassWord: "密码长度在8-14个字符"
            },
            confirm_password: {
                required: "请输入密码",
                isPassWord: "密码必须和上面一致",
                equalTo: "两次密码输入不一致"
            },
            phone_number: {
                required: "请输入电话号码",
                isPhone_number:'请输入正确手机号码'
            },
            code: {
                required: "请输入右侧验证码",
            },
            phone_code: {
                required: "请输入手机验证码",
            },
            tongyi: {
                required: "必须勾选同意才能注册",
            },
        }
    })
    // 自定义验证
    // 用户名验证   
    jQuery.validator.addMethod("isUserName", function (value, element) {
        var uName = /^[A-Za-z0-9_-]{6,12}$/;
        return this.optional(element) || (uName.test(value));
    });

    // 密码验证  再次确认密码和密码一致可以用一个  
    jQuery.validator.addMethod("isPassWord", function (value, element) {
        var psw = /^[A-Za-z0-9_-]{8,14}$/;
        return this.optional(element) || (psw.test(value));
    });

    //电话号码
    jQuery.validator.addMethod("isPhone_number", function (value, element) {
        var pum = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        return this.optional(element) || (pum.test(value));
    });
    
});